package pkg.chemdrm;

import java.util.ConcurrentModificationException;
import java.util.LinkedList;

import org.anddev.andengine.entity.shape.IShape;

public class EntityHandler {

	private LinkedList<Entity> mEntities; 
	private GameScene mGameScene;
	
	private LinkedList<AIRegion> mDoors;
	
	EntityHandler(final GameScene pGameScene)
	{
		mGameScene = pGameScene;
		mEntities = new LinkedList<Entity>();
	}
	
	public void spawnEntity(final Entity pEntity)
	{
		mEntities.add(pEntity);			
	}
	
	
	public void updateEntities(final float dt)
	{
		LinkedList<Entity> trash = new LinkedList<Entity>();
		
		try{
			for(Entity i : mEntities)
			{
				i.update(dt);
				if(!i.getExists())
					trash.add(i);
			}
		}
		catch(ConcurrentModificationException e)
		{
			// do nothin.
		}
		
		for(Entity i : trash)
		{
			mEntities.remove(i);
		}
	}
	
}
